package com.yonyou.common.dialog;

import com.intellij.notification.NotificationType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.yonyou.biz.vo.GitLogContext;
import com.yonyou.common.git.UniversityToolWindow;

import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import org.gitlab4j.api.GitLabApi;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.List;


/**
 * @author wengyongcheng
 * @since 2020/3/1 10:31 下午
 */
public class MyToolWindowFactory implements ToolWindowFactory, Condition<Project> {

    /**
     * 创建 tool window
     * @param project
     * @param toolWindow
     */
    private static final String DISPLAY_NAME = "代码合并";

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {

        try {
            GitRepository repository = GitBranchUtil.getCurrentRepository(project);

            UniversityToolWindow window = new UniversityToolWindow(new GitLogContext(project));
            ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();

            Content content = contentFactory.createContent(window, DISPLAY_NAME, false);
            content.setCloseable(false);
            toolWindow.getContentManager().addContent(content);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }


    /**
     * 控制tool window是否展示
     * @param project
     * @return
     */
    @Override
    public boolean value(Project project) {
        return true;
    }
}
